<?
require_once LIBS."ReversedProxy.class.php";

function process_comment_content($response) {
    $response = str_replace(array("http://www.blogger.com/static/v1/jsbin/2874331597-base_zh-CN.js","http://www.blogger.com/static/v1/v-css/1332657677-comment_bundle.css","/img/blank.gif","/comment.do","hellohtml5.blogspot.com"),array("http://cdn.doctype.info/blogger/2874331597-base_zh-CN.js","http://cdn.doctype.info/blogger/1332657677-comment_bundle.css","http://cdn.doctype.info/blogger/img/blank.gif","http://".SERVER_HOST."/".MAGIC_STR."comment/http://www.blog!ger.com/comment.do",SERVER_HOST),$response);
	$response .= "<script>var rpsv_root = document.getElementById(\"identity-options\"),rpsv_childs = document.getElementById(\"identity-options\").childNodes;rpsv_root.removeChild(rpsv_childs[0]);rpsv_root.removeChild(rpsv_childs[1]);document.getElementById(\"iden-anonymous\").setAttribute('checked','checked');</script>";
	//移除godaddy广告
    if($_SERVER["HTTP_ACCEPT_LANGUAGE"] == "zh-CN"){
        $response .= "<script>"; 
	}

	return $response;
}

function process_comment_header($header) {
	// 302跳转更改
    if (array_key_exists("Location", $header)) {
		$header["Location"] = "http://".SERVER_HOST."/".MAGIC_STR."comment/".$header["Location"];
    }
	return $header;
}

function blogspot_comment($url) {
    $method_post = count($_POST) > 0;
	if ($method_post) { // 提交评论
	    $client = new ReversedProxy($url, $_POST, "POST");
	} else { // 查看评论
	    $client = new ReversedProxy($url);
	}
	$client->setopt(RVSPOPT_PENDING_REMOVE_HOSTNAME_SPECIALCHARS,"!");
	$client->exec_proxy("process_comment_content","process_comment_header");
}
